home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / utils1 / hdnfojt.arj / HDWIN.CPP < prev   
C/C++ Source or Header  |  1993-11-23  |  12KB  |  385 lines

  1. // HDWIN.CPP contains the user interface code for HDINFO
  2. // HDINFO.CPP contains the actual hardware analysis functions
  3.  
  4. // If you compile this, you will find that the background
  5. // and button colours differ from mine.  This is due to the
  6. // fact that I have edited the application palette (in APP.H)
  7. // to colours which I prefer, and changed the coding of
  8. // TButton::drawState().  The changes are only cosmetic.
  9.  
  10. #define Uses_TEventQueue
  11. #define Uses_TEvent
  12. #define Uses_TApplication
  13. #define Uses_TKeys
  14. #define Uses_TRect
  15. #define Uses_TMenuBar
  16. #define Uses_TSubMenu
  17. #define Uses_TMenuItem
  18. #define Uses_TStatusLine
  19. #define Uses_TStatusItem
  20. #define Uses_TStatusDef
  21. #define Uses_TDeskTop
  22. #define Uses_TView
  23. #define Uses_TWindow
  24. #define Uses_TButton
  25. #define Uses_MsgBox
  26. #define Uses_TDialog
  27.  
  28. #include <tv.h>
  29. #include <conio.h>
  30. #include "hdinfo.h"
  31.  
  32. // hardware interface routines (in HDINFO.CPP)
  33. extern unsigned secbuf[2][256];
  34. extern void readcmos( void);
  35. extern void writecmos( void);
  36. extern int drive0, drive1;
  37. extern void readdrives(void);
  38.  
  39. // prototypes for various functions in this unit
  40. // all these do is display info
  41. void doDrive0( void);
  42. void doDrive1( void);
  43. void ExitInstructions( void);
  44. void printinfo( struct ideinfo *id);
  45. void printnodrive( void);
  46.  
  47. // constant for menu commands
  48. const int cmDrive0= 200;
  49. const int cmDrive1 = 201;
  50. const int cmAbout = 204;
  51.  
  52.  
  53. class TInfoWindow : public TWindow
  54.     {
  55.     public:
  56.         TInfoWindow( const TRect& r, const char *aTitle, short aNumber );
  57.     };
  58.  
  59. TInfoWindow *InfoWindow;
  60.  
  61. TInfoWindow::TInfoWindow( const TRect& bounds, const char *aTitle,
  62.                   short aNumber) :
  63.             TWindow( bounds, aTitle, aNumber),
  64.             TWindowInit( &TInfoWindow::initFrame )
  65.     {
  66.     // plain window with border - no controls at all
  67.     flags = 0;
  68.     options = 0;
  69.     };
  70.  
  71. class TControlDialog: public TDialog
  72.     // we could subclass TWindow instead of TDialog but we
  73.     // would then need to create a new Palette to handle
  74.     // buttons inserted on the Window (the button palette
  75.     // entries extend beyond the normal window palette)
  76.     {
  77.     public:
  78.         TControlDialog( const TRect& r, const char *aTitle);
  79.         void handleEvent( TEvent& event );
  80.  
  81.         TButton *ButtonDrive0;
  82.         TButton *ButtonDrive1;
  83.         TButton *ButtonExit;
  84.     };
  85.  
  86. TControlDialog::TControlDialog( const TRect& r, const char *aTitle):
  87.     TDialog( r, aTitle),    TWindowInit( &TInfoWindow::initFrame )
  88.     {
  89.     flags = 0;
  90.     ButtonDrive0 = new TButton( TRect(2, 2, 15, 4), "Drive ~C~", cmDrive0, bfDefault);
  91.     insert( ButtonDrive0);
  92.     ButtonDrive1 = new TButton( TRect(2, 4, 15, 6), "Drive ~D~", cmDrive1, bfNormal);
  93.     insert( ButtonDrive1);
  94.     ButtonExit = new TButton( TRect(2, 7, 15, 9), "E~x~it.",cmQuit,bfNormal);
  95.     insert( ButtonExit);
  96.     };
  97.  
  98. void TControlDialog::handleEvent( TEvent& event )
  99.     // override default dialog box message handling
  100.     {
  101.      int answer;
  102.  
  103.     TGroup::handleEvent(event);
  104.      if( event.what== evCommand )
  105.           switch (event.message.command)
  106.                 {
  107.                 case cmDrive0:                        // Menu command cmDrive0
  108.                     ButtonDrive0->select();        // highlight the Drive 0 button
  109.                     doDrive0();                        // print info for drive 0
  110.                     break;
  111.                 case cmDrive1:
  112.                     ButtonDrive1->select();        // as above for cmDrive0
  113.                     doDrive1();
  114.                     break;
  115.                 case cmQuit:
  116.                     ButtonExit->select();        // highlight the exit button
  117.                     answer = messageBoxRect( TRect( 31, 5, 64, 13), "Do you really want to Exit?", mfOKButton | mfCancelButton
  118.                                                 | mfConfirmation);
  119.                     if (answer == cmCancel)
  120.                         {
  121.                         clearEvent( event);        // if not exit
  122.                         ExitInstructions();        // redisplay exit instructions
  123.                         }
  124.                     break;
  125.                 case cmAbout:                        // do some advertising
  126.                     messageBoxRect (TRect( 28, 4, 65, 13),
  127.                                         "HDINFO - Hard Drive Information " \
  128.                                         "Copyright (c) 1993 James Thorpe " \
  129.                                         "CIS ID# 100035,101",
  130.                                         mfOKButton | mfInformation );
  131.  
  132.                     //    after the message box has been displayed
  133.                     // go back and redisplay the information which
  134.                     // lay underneath it.  ie. find which button
  135.                     // is highlighted and do what it requires
  136.  
  137.                     if ((ButtonDrive0->state & sfSelected) != 0)
  138.                         doDrive0();
  139.                     if ((ButtonDrive1->state & sfSelected) != 0)
  140.                         doDrive1();
  141.                     if ((ButtonExit->state & sfSelected) != 0)
  142.                         ExitInstructions();
  143.                     break;
  144.                 }
  145.      // now handle keyboard input.
  146.      // arrow keys and tab key can be used to move
  147.      // between controls.
  148.      else if( event.what == evKeyDown )
  149.             switch (event.keyDown.keyCode)
  150.                  {
  151.                      case  kbTab:
  152.                      case  kbRight:
  153.                      case  kbDown:
  154.                             // select the previous button
  155.                             selectNext(False);
  156.  
  157.                             // print info matching highlighted button
  158.                             if ((ButtonDrive0->state & sfSelected) != 0)
  159.                                 {
  160.                                 event.what = evCommand;
  161.                                 event.message.command = cmDrive0;
  162.                                 handleEvent( event );
  163.                                 }
  164.                             if ((ButtonDrive1->state & sfSelected) != 0)
  165.                                 {
  166.                                 event.what = evCommand;
  167.                                 event.message.command = cmDrive1;
  168.                                 handleEvent( event );
  169.                                 }
  170.                             if ((ButtonExit->state & sfSelected) != 0)
  171.                                 {
  172.                                 ExitInstructions();
  173.                                 }
  174.                           break;
  175.                      case  kbShiftTab:
  176.                      case  kbLeft:
  177.                      case  kbUp:
  178.                             // select the next button
  179.                             selectNext(True);
  180.  
  181.                             // print info matching highlighted button
  182.                             if ((ButtonDrive0->state & sfSelected) != 0)
  183.                                 {
  184.                                 event.what = evCommand;
  185.                                 event.message.command = cmDrive0;
  186.                                 handleEvent( event );
  187.                                 }
  188.                             if ((ButtonDrive1->state & sfSelected) != 0)
  189.                                 {
  190.                                 event.what = evCommand;
  191.                                 event.message.command = cmDrive1;
  192.                                 handleEvent( event );
  193.                                 }
  194.                             if ((ButtonExit->state & sfSelected) != 0)
  195.                                 ExitInstructions();
  196.                             break;
  197.                      case kbEnter:
  198.                         if ((ButtonExit->state & sfSelected) != 0)
  199.                             {
  200.                             event.what = evCommand;
  201.                             event.message.command = cmQuit;
  202.                             handleEvent( event );
  203.                             break;
  204.                             } //if
  205.                  } // switch
  206.      };
  207.  
  208.  
  209. class TMyApp : public TApplication
  210.     {
  211.     public:
  212.         TMyApp();
  213.         static TStatusLine *initStatusLine( TRect r );
  214.         static TMenuBar *initMenuBar( TRect r );
  215.     };
  216.  
  217. TMyApp::TMyApp() : TProgInit( &TMyApp::initStatusLine,
  218.                          &TMyApp::initMenuBar,
  219.                          &TMyApp::initDeskTop )
  220.     {
  221.     InfoWindow = new TInfoWindow( TRect( 23, 1, 76, 21), NULL, 0);
  222.     deskTop->insert(InfoWindow);
  223.     TControlDialog *ControlDialog = new TControlDialog( TRect( 2, 4, 19, 14), NULL);
  224.     deskTop->insert(ControlDialog);
  225.     ControlDialog->ButtonDrive0->select();        // set highlight flag
  226.     ControlDialog->ButtonDrive0->press();        // send message matching button so that
  227.                                                             // handleEvent() will then display the
  228.                                                             // data matching this button.
  229.     };
  230.  
  231. TStatusLine *TMyApp::initStatusLine(TRect r)
  232.     {
  233.     // the status line dispatches a cmAbout broadcast
  234.     // which brings up the About... dialog box
  235.     r.a.y = r.b.y - 1;     // move top to 1 line above bottom
  236.     return new TStatusLine( r,
  237.         *new TStatusDef( 0, 0xFFFF ) +
  238.             *new TStatusItem( "HDInfo version 1.2 - Copyright 1993 James Thorpe", 0, cmAbout, NULL ));
  239.     };
  240.  
  241. TMenuBar *TMyApp::initMenuBar( TRect r )
  242.     {
  243.     r.b.y = r.a.y + 1;    // set bottom line 1 line below top line
  244.     return new TMenuBar( r,
  245.         *new TSubMenu( "~F~ile", kbAltF )+
  246.             *new TMenuItem( "Drive ~C~", cmDrive0, 0, hcNoContext, "" )+
  247.             *new TMenuItem( "Drive ~D~",  cmDrive1, 0, hcNoContext, "" )+
  248.             newLine()+
  249.             *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "" )+
  250.         *new TSubMenu( "~A~bout", kbAltO )+
  251.             *new TMenuItem( "~A~bout HDINFO", cmAbout, 0, hcNoContext, "" ));
  252.     };
  253.  
  254.  
  255. int main( void)
  256.     {
  257.     readdrives();            // get info about hard drives
  258.     TMyApp myApp;            // bring up user interface
  259.     myApp.run();            // and display data
  260.     return 0;
  261.     }
  262.  
  263. // Herein start the utility routines which respond to the
  264. // interface code above.  Even though we are using the
  265. // CONIO screen output functions we still get the screen
  266. // colours for each function from the TWindow palette.
  267. // This should mean that we get a reasonable display
  268. // on colour and mono monitors and that it is
  269. // co-ordinated with the dialogs and windows.
  270.  
  271. void doDrive0( void)
  272. // display information about drive 0
  273.     {
  274.     struct ideinfo *id = (struct ideinfo *)secbuf[0];
  275.     TRect r = InfoWindow->getBounds();
  276.     window( r.a.x+3, r.a.y+3, r.b.x-1, r.b.y);
  277.     textattr( (char)InfoWindow->getColor( 0x0301));
  278.     clrscr();
  279.     textattr( (char)InfoWindow->getColor( 0x0304));
  280.     cputs("      SPECIFICATIONS FOR HARD DISK DRIVE C.      \n\n\r");
  281.     if (drive0 == 1)
  282.         printinfo( id);
  283.     else
  284.         printnodrive();
  285.     };
  286.  
  287. void doDrive1( void)
  288. // display information about drive 1
  289.     {
  290.     struct ideinfo *id = (struct ideinfo *)secbuf[1];
  291.  
  292.     TRect r = InfoWindow->getBounds();
  293.     window( r.a.x+3, r.a.y+3, r.b.x-1, r.b.y);
  294.     textattr( (char)InfoWindow->getColor( 0x0301));
  295.     clrscr();
  296.     textattr( (char)InfoWindow->getColor( 0x0304));
  297.     cputs("      SPECIFICATIONS FOR HARD DISK DRIVE D.      \n\n\r");
  298.     if (drive1 == 1)
  299.         printinfo( id);
  300.     else
  301.         printnodrive();
  302.     };
  303.  
  304. char *cont_type[] = { "Not specified",
  305.                             "Single port, Single sector buffer",
  306.                             "Dual port, Multi-sector buffer",
  307.                             "Dual port, Multi-sector buffer with cache",
  308.                             "Not specified" };
  309.  
  310. void printinfo(struct ideinfo *id)
  311.     // routine to print drive info
  312.     // doDrive0() and doDrive1() collect their respective
  313.     // parameters and come here to print them.
  314.     {
  315.     textattr( (char)InfoWindow->getColor( 0x0306));
  316.     cputs(   "DRIVE INDENTIFICATION\n\r");
  317.     textattr( (char)InfoWindow->getColor( 0x0302));
  318.     cprintf( "Model:    %.38s\n\r", id->model);
  319.     cprintf( "Firmware: %.8s\n\r", id->firmware);
  320.     cprintf( "Serial #: %.20s\n\n\r", id->serial);
  321.     textattr( (char)InfoWindow->getColor( 0x0306));
  322.     cputs(   "DRIVE CONTROLLER DETAILS\n\r");
  323.     textattr( (char)InfoWindow->getColor( 0x0302));
  324.     cprintf( "Type:   %s\n\r", cont_type[id->contype]);
  325.     cprintf( "Access: %u bit\n\n\r", id->dblword);
  326.     textattr( (char)InfoWindow->getColor( 0x0306));
  327.     cputs(   "DRIVE SPECIFICATIONS (According to:)\n\r");
  328.     textattr( (char)InfoWindow->getColor( 0x0302));
  329.     cprintf( "Drive: %#5u Cyls,%#3u Heads,%#3u Secs = %#8.2lfMb\n\r",
  330.                  id->fixcyls, id->heads, id->sectors, id->capacity);
  331.     cputs(   "BIOS:  ");
  332.     if (id->biosheads != (unsigned)-1)
  333.         cprintf( "%#5u Cyls,%#3u Heads,%#3u Secs = %#8.2lfMb\n\r",
  334.                  id->bioscyls, id->biosheads, id->biossecs, id->bioscapacity);
  335.     else
  336.         cputs("The BIOS does not recognise this drive.\n\r");
  337.     if( id->bioscapacity == id->capacity)
  338.         {
  339.         cputs( "\nThe current BIOS settings for this drive are\n\r" \
  340.                  "optimum settings, and give 100% utilisation of\n\r" \
  341.                  "the available physical disk space");
  342.         }
  343.     else
  344.         {
  345.         cprintf( "Theory:%#5u Cyls,%#3u Heads,%#3u Secs = %#8.2lfMb\n\r",
  346.                  id->bestcyls, id->bestheads, id->bestsecs, id->capacity);
  347.         cprintf( "\nThe theoretical BIOS settings will increase disk\n\r" \
  348.                     "capacity by %.2lfMb over current settings.", id->capacity - id->bioscapacity);
  349.         };
  350.     };
  351.  
  352. void printnodrive( void)
  353. // if no drive available then print message to that effect.
  354.     {
  355.     textattr( (char)InfoWindow->getColor( 0x0306));
  356.     cputs("\n\r" \
  357.             "    Analysis of the hardware indicates that\n\r" \
  358.             "    this drive is not installed.\n\n\r");
  359.     textattr( (char)InfoWindow->getColor( 0x0302));
  360.     cputs("    If this drive is installed then either\n\r" \
  361.             "    the drive is not an IDE drive or, there\n\r" \
  362.             "    is a fault in the drive hardware or\n\r" \
  363.             "    in the cabling."
  364.             );
  365.     };
  366.  
  367. void ExitInstructions( void)
  368. // tell the user to type ENTER to exit.
  369. // Add a warning about changing the CMOS settings.
  370.     {
  371.     TRect r = InfoWindow->getBounds();
  372.     window( r.a.x+3, r.a.y+3, r.b.x-1, r.b.y);
  373.     textattr( (char)InfoWindow->getColor( 0x0301));
  374.     clrscr();
  375.     textattr( (char)InfoWindow->getColor( 0x0306));
  376.     cputs("\n\n\n\n\n\r" \
  377.             "              Type ENTER to Exit.\n\r" );
  378.     textattr( (char)InfoWindow->getColor( 0x0302));
  379.     cputs("\n\n\n\r" \
  380.             "    WARNING: Do NOT alter the CMOS settings\n\r" \
  381.             "    for a hard drive that is currently in use,\n\r" \
  382.             "    unless you are prepared to reformat it and\n\r" \
  383.             "    reinstall all your software.");
  384.     };
  385.